/**
  http://people.sc.fsu.edu/~burkardt/cpp_src/bmp_io/bmp_io.html

 BMP_IO is a C++ library which reads or writes the graphics information in  a Microsoft BMP file.

A user program can employ these routines to read a BMP file and extract and return the graphics
 information (RGB pixel arrays), or to write internal RGB pixel arrays into a properly formatted BMP file.
 The BMP file format is used for many of the icons seen cluttering up the desktop of a Windows machine, for instance.

Of course, another interesting application is to read in a BMP file,
and write out the RGB information to a file in another format.

Since some of the data is multibyte, the format of the file can depend on whether
such data is written with the bytes in "little-endian" or "big-endian" order.
The program maintains a variable called BMP_BYTE_SWAP which controls how the
program assumes the bytes are ordered.
Setting this variable to true show be the appropriate value for little-endian ordering,
while false is for big-endian.
This variable can be read by calling the function bmp_byte_swap_get, or set by calling bmp_byte_swap_set.
Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

*/

using namespace std;

bool bmp_byte_swap_get ( void );
void bmp_byte_swap_set ( bool value );

bool bmp_08_data_read ( ifstream &file_in, unsigned long int width, long int height,
  unsigned char *rarray );
void bmp_08_data_write ( ofstream &file_out, unsigned long int width,
  long int height, unsigned char *rarray );

bool bmp_24_data_read ( ifstream &file_in, unsigned long int width,
  long int height, unsigned char *rarray, unsigned char *garray, unsigned char *barray );
void bmp_24_data_write ( ofstream &file_out, unsigned long int width,
  long int height, unsigned char *rarray, unsigned char *garray, unsigned char *barray );

void bmp_header1_print ( unsigned short int filetype,
  unsigned long int filesize, unsigned short int reserved1,
  unsigned short int reserved2, unsigned long int bitmapoffset );
bool bmp_header1_read ( ifstream &file_in, unsigned short int *filetype,
  unsigned long int *filesize, unsigned long int *reserved1,
  unsigned short int *reserved2, unsigned long int *bitmapoffset );
void bmp_header1_write ( ofstream &file_out, unsigned short int filetype,
  unsigned long int filesize, unsigned long int reserved1,
  unsigned short int reserved2, unsigned long int bitmapoffset );

void bmp_header2_print ( unsigned long int size, unsigned long int width,
  long int height,
  unsigned short int planes, unsigned short int bitsperpixel,
  unsigned long int compression, unsigned long int sizeofbitmap,
  unsigned long int horzresolution, unsigned long int vertresolution,
  unsigned long int colorsused,  unsigned long int colorsimportant );
bool bmp_header2_read ( ifstream &file_in, unsigned long int *size,
  unsigned long int *width, long int *height,
  unsigned short int *planes, unsigned short int *bitsperpixel,
  unsigned long int *compression, unsigned long int *sizeofbitmap,
  unsigned long int *horzresolution, unsigned long int *vertresolution,
  unsigned long int *colorsused, unsigned long int *colorsimportant );
void bmp_header2_write ( ofstream &file_out, unsigned long int size,
  unsigned long int width, long int height,
  unsigned short int planes, unsigned short int bitsperpixel,
  unsigned long int compression, unsigned long int sizeofbitmap,
  unsigned long int horzresolution, unsigned long int vertresolution,
  unsigned long int colorsused, unsigned long int colorsimportant );

void bmp_palette_print ( unsigned long int colorsused,
  unsigned char *rparray, unsigned char *gparray, unsigned char *bparray,
  unsigned char *aparray );
bool bmp_palette_read ( ifstream &file_in, unsigned long int colorsused,
  unsigned char *rparray, unsigned char *gparray, unsigned char *bparray,
  unsigned char *aparray );
void bmp_palette_write ( ofstream &file_out, unsigned long int colorsused,
  unsigned char *rparray, unsigned char *gparray, unsigned char *bparray,
  unsigned char *aparray );

bool bmp_print_test ( char *file_in_name );

bool bmp_read ( char *file_in_name, unsigned long int *width, long int *height,
  unsigned char **rarray, unsigned char **garray, unsigned char **barray );
bool bmp_read_test ( char *file_in_name );

bool bmp_08_write ( char *file_out_name, unsigned long int width, long int height,
  unsigned char *rarray, unsigned char *garray, unsigned char *barray );
bool bmp_08_write_test ( char *file_out_name );

bool bmp_24_write ( char *file_out_name, unsigned long int width, long int height,
  unsigned char *rarray, unsigned char *garray, unsigned char *barray );
bool bmp_24_write_test ( char *file_out_name );

bool long_int_read ( long int *long_int_val, ifstream &file_in );
void long_int_write ( long int long_int_val, ofstream &file_out );

bool u_long_int_read ( unsigned long int *u_long_int_val, ifstream &file_in );
void u_long_int_write ( unsigned long int u_long_int_val, ofstream &file_out );

bool u_short_int_read ( unsigned short int *u_short_int_val, ifstream &file_in );
void u_short_int_write ( unsigned short int u_short_int_val, ofstream &file_out );
